package pl.smath.operation.basic;

import java.util.List;

import junit.framework.TestCase;
import pl.smath.expression.ProductTerm;
import pl.smath.expression.SumTerm;
import pl.smath.expression.Term;
import pl.smath.operation.BasicOp;
import pl.smath.parser.ExpressionParser;


public class MultiplyAddTestCase extends TestCase {

	/** 
	 * Test data. Format:
	 * input => expected output 
	 */
	private static final String[][] testData = {
		 {"2*(a+b)","2*a+2*b"},
         {"2*(-a-b)","-2*a-2*b"},
         {"(a+b)*(c+d)","a*c+a*d+b*c+b*d"}
	};
	
	
	public void testData() {
		ExpressionParser parser = new ExpressionParser();
		Term	input;
		Term	output;
		
		for(int i = 0; i < testData.length; i++){
		
			input = parser.parseText( testData[i][0] );
			output = input;
			if(input instanceof ProductTerm){
				List<Term> terms = ((ProductTerm)input).getTermsList();
				if(terms.size() == 2)
					output = BasicOp.multiplyAdd( terms.get(0), (SumTerm)terms.get(1) );
			}
			
			assertEquals("Input: " + testData[i][0], testData[i][1], output.toString());
		}
	}
	
}
